package org.dromara.system.dict.controller;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.system.dict.domain.IndicatorFactor;
import org.dromara.system.dict.domain.IndicatorType;
import org.dromara.system.dict.domain.UnitType;
import org.dromara.system.dict.service.DictService;
import org.springframework.web.bind.annotation.*;
import software.amazon.awssdk.core.Response;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 字典服务
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/system")
public class DictController {

    private final DictService dictService;


    /**
     * 根据传感器类型编码查询传感器监测因子列表
     *
     * @see 102.100.56
     */
    @GetMapping("/query/match/list/indicator_factor/{indicatorTypeCode}")
    public R<Map<String, String>> queryIndicatorFactorList(@PathVariable String indicatorTypeCode) {
        List<IndicatorFactor> indicatorFactorList = dictService.queryIndicatorFactorByCode(indicatorTypeCode);
        Map<String, String> returnMap = indicatorFactorList.stream().collect(Collectors.toMap(IndicatorFactor::getCode, IndicatorFactor::getName));
        return R.ok(returnMap);
    }

    /**
     * 获取传感器类型列表
     */
    @GetMapping("/query/match/list/indicator_type")
    public R<Map<String, String>> queryIndicatorTypeList() {
        List<IndicatorType> indicatorTypeList = dictService.queryIndicatorTypeList();
        Map<String, String> returnMap = indicatorTypeList.stream().collect(Collectors.toMap(IndicatorType::getCode, IndicatorType::getName));
        return R.ok(returnMap);
    }

    /**
     * 获取参数单位类型列表
     */
    @GetMapping("/query/match/list/unit_type")
    public R<Map<String, String>> queryUnitTypeList() {
        List<UnitType> list = dictService.queryUnitTypeList();
        Map<String, String> returnMap = list.stream().collect(Collectors.toMap(UnitType::getCode, UnitType::getName));
        return R.ok(returnMap);
    }
}
